﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace ScoreManage
{
    public partial class Teacher : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindGrid();
        }

        protected void BindGrid()
        {
            string strConn = ConfigurationManager.ConnectionStrings["studbConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConn);
            string strSql = string.Format("SELECT * FROM sctview WHERE tno='{0}'", Session["ID"]);
            SqlCommand myCommand = new SqlCommand(strSql, conn);
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            da.Fill(ds, "sctview");
            GridView1.DataSource = ds.Tables["sctview"];
            GridView1.DataBind();
        }

        /*
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            Response.Redirect("TeacherGradeInsert.aspx");
        }

        
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            string parmString = ((LinkButton)sender).CommandArgument.ToString();
            string[] parmStr = parmString.Split(',');
            string Cno = parmStr[0];
            string Sno = parmStr[1];
            string strConn = ConfigurationManager.ConnectionStrings["studbConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            string strSql = string.Format("DELETE student_course WHERE cno='{0}' AND sno='{1}'", Cno, Sno);
            SqlCommand myCommand = new SqlCommand(strSql, conn);
            myCommand.ExecuteNonQuery();
            BindGrid();
        }
        */

        protected void btnQueryByCname_Click(object sender, EventArgs e)
        {
            string course_name = txtQuery.Text.Trim().Replace("'", "''");
            string strConn = ConfigurationManager.ConnectionStrings["studbConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConn);
            string strSql = string.Format("SELECT * FROM sctview WHERE cname LIKE '%{0}%' AND tno='{1}'", course_name, Session["ID"]);
            SqlCommand myCommand = new SqlCommand(strSql, conn);
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            da.Fill(ds, "sctview");
            GridView1.DataSource = ds.Tables["sctview"];
            GridView1.DataBind();
        }

        protected void btnQueryBySno_Click(object sender, EventArgs e)
        {
            string sno = txtQuery.Text.Trim().Replace("'", "''");
            string strConn = ConfigurationManager.ConnectionStrings["studbConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConn);
            string strSql = string.Format("SELECT * FROM sctview WHERE sno LIKE '%{0}%' AND tno='{1}'", sno, Session["ID"]);
            SqlCommand myCommand = new SqlCommand(strSql, conn);
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            da.Fill(ds, "sctview");
            GridView1.DataSource = ds.Tables["sctview"];
            GridView1.DataBind();
        }

        protected void btnShowAll_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
    }
}